package com.kaiwukj.android.ufamily.mvp.ui.page.mine.evaluate;

import androidx.annotation.NonNull;

import com.kaiwukj.android.mcas.di.scope.ActivityScope;
import com.kaiwukj.android.mcas.mvp.BasePresenter;
import com.kaiwukj.android.mcas.utils.RxLifecycleUtils;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.base.ListResp;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.OrderEvaluateResult;
import com.kaiwukj.android.ufamily.mvp.http.utils.RxUtils;
import com.kaiwukj.android.ufamily.mvp.ui.page.order.OrderContract;

import javax.inject.Inject;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;

@ActivityScope
public class EvaluatePresenter extends BasePresenter<OrderContract.Model, OrderContract.EvaluateView> {

    @Inject
    RxErrorHandler mErrorHandler;

    @Inject
    public EvaluatePresenter(OrderContract.Model model, OrderContract.EvaluateView view) {
        super(model, view);
    }

    public void fetchNotEvaluate(int page, int pageSize) {
        mModel.fetchEvaluate(page, pageSize, 1)
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<ListResp<OrderEvaluateResult>>(mErrorHandler, mRootView) {
                    @Override
                    public void onSuccess(@NonNull ListResp<OrderEvaluateResult> result) {
                        mRootView.onFetchResult(result.getList());
                    }
                });
    }

    public void fetchEvaluate(int page, int pageSize) {
        mModel.fetchEvaluate(page, pageSize, 2)
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<ListResp<OrderEvaluateResult>>(mErrorHandler, mRootView) {
                    @Override
                    public void onSuccess(@NonNull ListResp<OrderEvaluateResult> result) {
                        mRootView.onFetchResult(result.getList());
                    }
                });
    }

}
